//
//  IGTopicBottomCell.m
//  jingdongfang
//
//  Created by BOE on 2017/12/14.
//  Copyright © 2017年 LJL. All rights reserved.
//

#import "IGTopicBottomCell.h"
#import "IGTopicModel.h"
#import "IGCommunityDetailVC.h"

static NSString *const kIGTopicBottomCellID = @"kIGTopicBottomCellID";
@interface IGTopicBottomCell()

@property (nonatomic, strong) UILabel *communityLabel;//圈子名称

@property (nonatomic, strong) UIButton *goodBtn;//点赞按钮
@property (nonatomic, strong) UILabel *goodNumLabel;//点赞数

@end

@implementation IGTopicBottomCell

+ (IGTopicBottomCell *)cellWithTableView:(UITableView *)tableView {
    IGTopicBottomCell *cell = [tableView dequeueReusableCellWithIdentifier:kIGTopicBottomCellID];
    if (!cell) {
        cell = [[IGTopicBottomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kIGTopicBottomCellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor c3Color];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self createUI];
    }
    return self;
}

- (void)createUI {
    __weak typeof(self) weakSelf = self;
    
    //点赞 点赞数+点赞图标
    self.goodNumLabel = [UILabel new];
    [self.contentView addSubview:self.goodNumLabel];
    self.goodNumLabel.font = [UIFont font12];
    self.goodNumLabel.textColor = [UIColor c5Color];
    self.goodNumLabel.textAlignment = NSTextAlignmentLeft;
    [self.goodNumLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kGAP10);
        make.top.mas_equalTo(0);
        make.width.height.mas_equalTo(18);
    }];
    
    self.goodBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.goodBtn setImage:[UIImage imageNamed:@"赞"] forState:UIControlStateNormal];
    [self.goodBtn setImage:[UIImage imageNamed:@"赞_蓝"] forState:UIControlStateSelected];
    [self.contentView addSubview:self.goodBtn];
    [self.goodBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.goodNumLabel.mas_left).offset(-kGAP6);
        make.top.mas_equalTo(0);
        make.width.height.mas_equalTo(18);
    }];
    
    UIView *goodView = [UIView new];
    goodView.userInteractionEnabled = YES;
    [goodView setTapActionWithBlock:^{
        if (weakSelf.likeBlock) {
            weakSelf.likeBlock();
        }
    }];
    [self.contentView addSubview:goodView];
    [goodView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_goodBtn.mas_left);
        make.right.mas_equalTo(_goodNumLabel.mas_right);
        make.top.mas_equalTo(_goodBtn.mas_top).mas_offset(-10);
        make.bottom.mas_equalTo(_goodBtn.mas_bottom).mas_offset(10);
    }];
    
}

- (void)setTopicModel:(IGTopicModel *)topicModel {
    _topicModel = topicModel;
    
    //点赞数
    _goodNumLabel.text = topicModel.zanNums;
    CGFloat zanW = [topicModel.zanNums boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 18) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont font12]} context:nil].size.width + 0.5;
    
    [self.goodNumLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(zanW);
    }];
    
    _goodBtn.selected = topicModel.isZan;
}

+ (CGFloat)cellHeight {
    return 18 + 15;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
